$(function(){
	var $modal = $('#my-modal-loading');
	$("#blacklist").click(function(){
		location.href = "topic_permission.html";
	});
	var query_id = localStorage.getItem("query_id");
	var urlPath = "http://yx.fxtourong.com/V1/Circle/isNeedApproval" + "?store_id=" + query_id; 
	var urlPath2 = "http://yx.fxtourong.com/V1/Circle/setSearch" + "?store_id=" + query_id;
	var urlPath3 = "http://yx.fxtourong.com/V1/Circle/getCircleStatus" + "?store_id=" + query_id;
	
	$modal.modal();
	$.ajax({
			type: "POST",
			url: urlPath3,
			data: {
				token: localStorage.getItem("token")
			},
			dataType: "json",
			success: function(data) {
				$modal.modal('close');
				console.log(data);
				var code = data.code;
				console.log(code);
				if(code == "1") {
					var approval = data.data.approval;
					var is_search = data.data.is_search;
					if(approval == "0"){
						honeySwitch.showOff("#switchSp")
					} else {
						honeySwitch.showOn("#switchSp")
					}
					if(is_search == "0"){
						honeySwitch.showOff("#switchSearch")
					} else {
						honeySwitch.showOn("#switchSearch")
					}
				} else {
					alert(data.message + "");
					window.history.back(-1);
				}
			},
			error: function(e){
				$modal.modal('close');
				alert("服务请求异常！")
			}
		});	
	
	switchEvent("#switchSp",function(){
		setSwitch("1");
	},function(){
		setSwitch("0");
	});
	
	switchEvent("#switchSearch",function(){
		setSwitch2("1");
	},function(){
		setSwitch2("0");
	});
	
	function setSwitch(index){
		$modal.modal();
		$.ajax({
			type: "POST",
			url: urlPath,
			data: {
				token: localStorage.getItem("token"),
				approval: index
			},
			dataType: "json",
			success: function(data) {
				$modal.modal('close');
				console.log(data);
				var code = data.code;
				console.log(code);
				if(code == "1") {
					new Toast({context:$('body'),message:'设置成功'}).show();
				} else {
					alert(data.message + "");
				}
			},
			error: function(e){
				$modal.modal('close');
				alert("服务请求异常！")
			}
		});
	}
	
	function setSwitch2(index){
		$modal.modal();
		$.ajax({
			type: "POST",
			url: urlPath2,
			data: {
				token: localStorage.getItem("token"),
				is_search: index
			},
			dataType: "json",
			success: function(data) {
				$modal.modal('close');
				console.log(data);
				var code = data.code;
				console.log(code);
				if(code == "1") {
					new Toast({context:$('body'),message:'设置成功'}).show();
				} else {
					alert(data.message + "");
				}
			},
			error: function(e){
				$modal.modal('close');
				alert("服务请求异常！")
			}
		});
	}
		
});
